#ifndef STATISTICS_
#define STATISTICS_
#include "ParseTree.h"
#include <tr1/unordered_map>
#include <string>
#include <iostream>
#include <utility>
#include <stdio.h>

using namespace std;

class Relation
{
public:
	//char *name;
	std::tr1::unordered_map<string, int> attrs;
	bool isSingleton;
	int numAttrs;
	double numTuples, JnumTuples, EnumTuples;
	string setName, JsetName;
	Relation();
	~Relation();
};

struct RelData
{
        Relation *rel;
        string name;
        int count;
};

class Statistics
{
	std::tr1::unordered_map<string, Relation*> relations;
	int numRels;

public:
	Statistics();
	Statistics(Statistics &copyMe);	 // Performs deep copy
	~Statistics();

	RelData findAtt(string att, char *relNames[], int numToJoin);
	void AddRel(char *relName, int numTuples);
	void AddAtt(char *relName, char *attName, int numDistincts);
	void CopyRel(char *oldName, char *newName);
	
	void Read(char *fromWhere);
	void Write(char *fromWhere);

	void  Apply(struct AndList *parseTree, char *relNames[], int numToJoin);
	double Estimate(struct AndList *parseTree, char **relNames, int numToJoin);
	bool validate(char ** relNames, int numToJoin);

};

#endif
